package demo1;

class Array<E extends Comparable<E>>{     //此处不是实现接口而是限定泛型类型的'上界'，表示E必须是Comparable<E>的子类，E支持Comparable功能
    public Object[] ay=new Object[6];
    public void setay(int pos,E val){
         ay[pos]=val;
    }
    public E getay(int pos){
        return (E)ay[pos];
    }
    public E max() {
        E max1 = (E)ay[0];
        for (int i = 0; i < ay.length; i++) {   //实现比较找出最大值
            if (max1.compareTo((E)ay[i]) < 0) {
                max1 = (E)ay[i];
            }
        }
        return max1;
    }
}
public class Test63one {
    public static void main(String [] args){
        Array<Integer>  ay2=new Array<>();//ay是对象
        /*Array<Integer> ay2=new Array<Integer>()与上等同*/
        ay2.setay(0,1);
        ay2.setay(1,2);
        ay2.setay(2,3);
        ay2.setay(3,4);
        ay2.setay(4,5);
        ay2.setay(5,7);
        int a=ay2.getay(0);
        int b=ay2.getay(1);
        System.out.println(a);
        System.out.println(b);
      int value=ay2.max();
      System.out.println(value);
    }

}
